package cn.icatw.leetcode.editor.cn.juc;

/**
 * @author 王顺 762188827@qq.com
 * @apiNote 三个线程顺序执行
 * @since 2024/8/14
 */
public class JoinTest {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("线程1执行");
        }, "线程1");
        Thread t2 = new Thread(() -> {
            try {
                t1.join();
                System.out.println("线程2执行");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }, "线程2");
        Thread t3 = new Thread(() -> {
            try {
                t2.join();
                System.out.println("线程3执行");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }, "线程3");
        t1.start();
        t2.start();
        t3.start();
    }
}
